{php $newUI = true;}
{template 'common/header'}
<div class="main">
	<ul class="nav nav-tabs">
		<li {if $_GPC['do'] == 'membercard'}class="active"{/if}><a href="{php echo $this->createWeburl('membercard', array('op' => 'display'))}">会员卡设置</a></li>
		<li {if $_GPC['do'] == 'signmanage'}class="active"{/if}><a href="{php echo $this->createWeburl('signmanage', array('op' => 'sign_set'))}">签到管理</a></li>
		<li {if $_GPC['do'] == 'noticemanage'}class="active"{/if}><a href="{php echo $this->createWeburl('noticemanage', array('op' => 'list'))}">通知管理</a></li>
		<li {if $_GPC['do'] == 'cardmanage'}class="active"{/if}><a href="{php echo $this->createWeburl('cardmanage', array('op' => 'display'))}">会员卡管理</a></li>
	</ul>
	<div style="margin-bottom:15px;">
		<div class="btn-group">
			<a href="{php echo $this->createWeburl('signmanage', array('op' => 'sign_set'))}" class="btn {if $op == 'sign_set'}btn-primary{else}btn-default{/if}">签到策略</a>
			<a href="{php echo $this->createWeburl('signmanage', array('op' => 'sign_record'))}" class="btn {if $op == 'sign_record'}btn-primary{else}btn-default{/if}">签到列表</a>
		</div>
	</div>
	{if $op == 'sign_record'}
	<div class="clearfix">
		<div class="form-group">
			<div class="panel panel-default">
				<div class="panel-body table-responsive">
					<table class="table table-hover">
						<thead>
						<tr>
							<th>会员姓名</th>
							<th>获得积分</th>
							<th>年</th>
							<th>月</th>
							<th>日</th>
							<th>补签</th>
							<th>签到时间</th>
						</tr>
						</thead>
						<tbody>
						{loop $list $sign}
						<tr>
							<td>{$sign['realname']}</td>
							<td>{$sign['credit']}</td>
							<td>{$sign['year']}</td>
							<td>{$sign['month']}</td>
							<td>{$sign['day']}</td>
							{if $sign['remedy'] == 1}
							<td>是</td>
							{else}
							<td>否</td>
							{/if}
							<td>{$sign['addtime']}</td>
						</tr>
						{/loop}
						</tbody>
					</table>
				</div>
			</div>
		{$pager}
		</div>
	</div>
	{/if}
	
	{if $op == 'sign_set'}
	<div class="clearfix">
		<div style="margin-bottom:20px">
			是否开启签到功能:
			<input type="checkbox" name="status" value="1" {if intval($extend_switch['sign'])==1} checked="checked" {/if}/>
		</div>
		{if $extend_switch['sign'] == '1'}
		<form action="" class="form-horizontal form" method="post" enctype="multipart/form-data" id="form1">
			<div class="panel panel-default">
				<div class="panel-heading">签到策略</div>
				<div class="panel-body">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">补签规则设置</label>
						<div class="col-sm-9 col-xs-12">
							<div class="input-group">
								<span class="input-group-addon">补签开启</span>
								<span class="form-control">
									<input style="margin-top:-6px;" type="checkbox" class="form-control" name="remedy" value="1" {if $sign_set['sign']['remedy'] == 1}checked{/if}/>
								</span>
								<span class="input-group-addon">补签扣除（每天/次）</span>
									<input type="text" class="form-control" name="remedy_cost" value="{$sign_set['sign']['remedy_cost']}"/>
								<span class="input-group-addon">
									<label class="radio-inline">
										<input type="radio" name="remedy_cost_type" value="credit2" {if $sign_set['sign']['remedy_cost_type'] == "credit2"}checked{/if}/>余额
									</label>
									<label class="radio-inline">
										<input type="radio" name="remedy_cost_type" value="credit1" {if $sign_set['sign']['remedy_cost_type'] == "credit1"}checked{/if}/>积分
									</label>
								</span>
							</div>
							</br>
						</div>
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">签到奖励</label>
						<div class="col-sm-9 col-xs-12">
							<div class="input-group">
								<span class="input-group-addon">每天签到奖励</span>
								<input type="text" class="form-control" name="everydaynum" value="{$sign_set['sign']['everydaynum']}"/>
								<span class="input-group-addon">积分</span>
							</div>
							<br/>
							<div class="input-group">
								<span class="input-group-addon">每月累计</span>
								<input type="text" class="form-control" name="first_group_day" value="{$sign_set['sign']['first_group_day']}"/>
								<span class="input-group-addon">天额外奖励</span>
								<input type="text" class="form-control" name="first_group_num" value="{$sign_set['sign']['first_group_num']}"/>
								<span class="input-group-addon">积分</span>
							</div>
							<br/>
							<div class="input-group">
								<span class="input-group-addon">每月累计</span>
								<input type="text" class="form-control" name="second_group_day" value="{$sign_set['sign']['second_group_day']}"/>
								<span class="input-group-addon">天额外奖励</span>
								<input type="text" class="form-control" name="second_group_num" value="{$sign_set['sign']['second_group_num']}"/>
								<span class="input-group-addon">积分</span>
							</div>
							<br/>
							<div class="input-group">
								<span class="input-group-addon">每月累计</span>
								<input type="text" class="form-control" name="third_group_day" value="{$sign_set['sign']['third_group_day']}"/>
								<span class="input-group-addon">天额外奖励</span>
								<input type="text" class="form-control" name="third_group_num" value="{$sign_set['sign']['third_group_num']}"/>
								<span class="input-group-addon">积分</span>
							</div>
							<br/>
							<div class="input-group">
								<span class="input-group-addon">每月满签额外奖励</span>
								<input type="text" class="form-control" name="full_sign_num" value="{$sign_set['sign']['full_sign_num']}"/>
								<span class="input-group-addon">积分</span>
							</div>
							<span class="help-block">连续奖励的天数必须大于1天。</span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">签到攻略</label>
						<div class="col-sm-9 col-xs-12">
							{php echo tpl_ueditor('content', $sign_set['content']);}
						</div>
					</div>
				</div>
			</div>
			<div class="form-group" style="margin-left:0px">
				<input type="hidden" name="token" value="{$_W['token']}"/>
				<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"/>
			</div>
		</form>
		{/if}
	</div>
</div>
<script type="text/javascript">
	require(['jquery.ui', 'bootstrap.switch'], function(){
		$('#form1').submit(function(){
			var everydaynum = parseInt($(':text[name="everydaynum"]').val());
			if(isNaN(everydaynum) || !everydaynum) {
				util.message('每天签到奖励积分必须大于0', '', 'error');
				return false;
			}
		});

		$(":checkbox[name='status']").bootstrapSwitch();
		$(":checkbox[name='status']").on('switchChange.bootstrapSwitch', function(e, state){
			$this = $(this);
			var status = this.checked ? 1 : 2;
			$.post("{php echo $this->createWeburl('signmanage', array('op' => 'sign_status'));}", {status:status}, function(data){
				data = $.parseJSON(data);
				if(data.message.errno != 0) {
					util.message(data.message.message, '', 'error');
					return false;
				} else {
					util.message('操作成功', location.href, 'success');
				}
			});
		});
	});
</script>
{/if}
{template 'common/footer'}
